function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	// 窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	// 弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}

$(function() {
	$(".pop_box").easydrag();
	$(".pop_box").setHandler(".pop_box .p_head");
});

function clickEditContract(id, div_id) {
	
	$("#empid_edit").val($("#t_em").text());
	$("#contractno_edit").val($("#t_cn").text());
	$("#starttime_edit").val($("#t_st").text());
	$("#endtime_edit").val($("#t_et").text());
	$("#duty_edit").val($("#t_du").text());
	$("#content_edit").val($("#t_co").text());
	$("#supplement_edit").val($("#t_su").text());

	$("#dossierid").val(id);
	popupDiv(div_id);
}

function addContract() {
	alert(1);
	var empid = $("#empid_add").val();
	var contractno = $("#contractno_add").val();
	var starttime = $("#starttime_add").val();
	var endtime = $("#endtime_add").val();
	var duty = $("#duty_add").val();
	var content = $("#content_add").val();
	var supplement = $("#supplement_add").val();

	if (empid && contractno && starttime && duty && content && supplement) {
		alert(2);
		ContractManager.addContract(empid , contractno , starttime , emdtime , duty , content ,
				supplement, function(data) {
					if (data) {
						alert("增加成功");
						location.reload("/getContractServlet");
					} else {
						alert("增加失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function updateContract() {
	
	var empid = $("#empid_edit").val();
	var contractno = $("#contractno_edit").val();
	var starttime = $("#starttime_edit").val();
	var endtime = $("#endtime_edit").val();
	var duty = $("#duty_edit").val();
	var content = $("#content_edit").val();
	var supplement = $("#supplement_edit").val();
	var id = $("#dossierid").val();	

	if (empid && contractno && starttime && endtime && duty && content && supplement) {
		ContractManager.updateContract(id, empid , contractno , starttime , emdtime , duty , content ,
				supplement, function(data) {
					if (data) {
						alert("修改成功");
						location.reload("/GetAllContractServlet");
					} else {
						alert("修改失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function deleteContract(id) {
	ContractManager.deleteById(id, function(data) {
		if (data) {
			alert("修改成功");
			location.reload("/GetAllContractServlet");
		} else {
			alert("修改失败");
		}
	});
}